<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>房屋及车位信息管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {
	        $('#builddate').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
		});

		function save() {
            var isValidate = true;//校验表单
            if(!isValidate){
                return false;
			}else{
                jp.loading();
                jp.post("${ctx}/property/buildinfo/propertyBuildinginfo/savecar",$('#inputForm').serialize(),function(data){
                    if(data.success){
                        jp.getParent().refresh();
                        var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(dialogIndex);
                        jp.success(data.msg)

                    }else{
                        jp.error(data.msg);
                    }
                })
			}

        }
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="propertyBuildinginfo" action="${ctx}/property/buildinfo/propertyBuildinginfo/savecar" method="post" class="form-horizontal">
		<form:hidden path="id"/>
			<div id="tab-1" class="tab-pane fade in  active">
				<a class="btn btn-white btn-sm" onclick="addRow('#propertyCarinfoList', propertyCarinfoRowIdx, propertyCarinfoTpl);propertyCarinfoRowIdx = propertyCarinfoRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
				<table class="table table-striped table-bordered table-condensed">
					<thead>
					<tr>
						<th class="hide"></th>
						<th>备注信息</th>
						<th><font color="red">*</font>业主名称</th>
						<th><font color="red">*</font>汽车类型</th>
						<th><font color="red">*</font>停车类型</th>
						<th>停车时间起</th>
						<th>停车时间止</th>
						<th><font color="red">*</font>车牌号</th>
						<th width="10">&nbsp;</th>
					</tr>
					</thead>
					<tbody id="propertyCarinfoList">
					</tbody>
				</table>
				<script type="text/template" id="propertyCarinfoTpl">//<!--
				<tr id="propertyCarinfoList{{idx}}">
					<td class="hide">
						<input id="propertyCarinfoList{{idx}}_id" name="propertyCarinfoList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="propertyCarinfoList{{idx}}_delFlag" name="propertyCarinfoList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

					<td>
						<textarea id="propertyCarinfoList{{idx}}_remarks" name="propertyCarinfoList[{{idx}}].remarks" rows="4"    class="form-control ">{{row.remarks}}</textarea>
					</td>


					<td  class="max-width-250">
						<sys:userselect id="propertyCarinfoList{{idx}}_houseowner" name="propertyCarinfoList[{{idx}}].houseowner.id" value="{{row.houseowner.id}}" labelName="propertyCarinfoList{{idx}}.houseowner.name" labelValue="{{row.houseowner.name}}"
							    cssClass="form-control required"/>
					</td>


					<td>
						<select id="propertyCarinfoList{{idx}}_cartype" name="propertyCarinfoList[{{idx}}].cartype" data-value="{{row.cartype}}" class="form-control m-b  required">
							<option value=""></option>
							<c:forEach items="${fns:getDictList('car_type')}" var="dict">
								<option value="${dict.value}">${dict.label}</option>
							</c:forEach>
						</select>
					</td>


					<td>
						<select id="propertyCarinfoList{{idx}}_carparktype" name="propertyCarinfoList[{{idx}}].carparktype" data-value="{{row.carparktype}}" class="form-control m-b  required">
							<option value=""></option>
							<c:forEach items="${fns:getDictList('car_park_type')}" var="dict">
								<option value="${dict.value}">${dict.label}</option>
							</c:forEach>
						</select>
					</td>


					<td>
						<div class='input-group form_datetime' id="propertyCarinfoList{{idx}}_parkstarttime">
		                    <input type='text'  name="propertyCarinfoList[{{idx}}].parkstarttime" class="form-control "  value="{{row.parkstarttime}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>


					<td>
						<div class='input-group form_datetime' id="propertyCarinfoList{{idx}}_parkendtime">
		                    <input type='text'  name="propertyCarinfoList[{{idx}}].parkendtime" class="form-control "  value="{{row.parkendtime}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>


					<td>
						<input id="propertyCarinfoList{{idx}}_Carno" name="propertyCarinfoList[{{idx}}].Carno" type="text" value="{{row.Carno}}"    class="form-control required"/>
					</td>

					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#propertyCarinfoList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
				</script>
				<script type="text/javascript">
                    var propertyCarinfoRowIdx = 0, propertyCarinfoTpl = $("#propertyCarinfoTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                    $(document).ready(function() {
                        var data = ${fns:toJson(propertyBuildinginforty.propertyCarinfoList)};
                        for (var i=0; i<data.length; i++){
                            addRow('#propertyCarinfoList', propertyCarinfoRowIdx, propertyCarinfoTpl, data[i]);
                            propertyCarinfoRowIdx = propertyCarinfoRowIdx + 1;
                        }
                    });
				</script>
			</div>
		</form:form>
</body>
</html>